import request from '@/config/axios'
import type { Dayjs } from 'dayjs';

/** 机器模具信息 */
export interface BasicMachineMould {
  id: number; // 编号
  machineId?: number; // 机器id
  mouldId?: number; // 模具id
}

/** ERP 基础资料模具信息 */
export interface BasicMachine {
  id: number; // 机器编号
  name?: string; // 机器名称
  code: string; // 编码
  status?: number; // 机器状态
  purchaseUserId: number; // 采购人
  purchaseTime: string | Dayjs; // 采购日期
  purchasePrice: number; // 采购价格
  remark: string; // 备注
  basicMachineMoulds?: BasicMachineMould[]
}

// ERP 基础资料模具 API
export const BasicMachineApi = {
  // 查询ERP 基础资料模具分页
  getBasicMachinePage: async (params: any) => {
    return await request.get({ url: `/erp/basic-machine/page`, params })
  },

  getBasicMachineSimpleList: async (params: any) => {
    return await request.get({url: `/erp/basic-machine/simple-list`, params})
  },

  // 查询ERP 基础资料模具详情
  getBasicMachine: async (id: number) => {
    return await request.get({ url: `/erp/basic-machine/get?id=` + id })
  },

  // 新增ERP 基础资料模具
  createBasicMachine: async (data: BasicMachine) => {
    return await request.post({ url: `/erp/basic-machine/create`, data })
  },

  // 修改ERP 基础资料模具
  updateBasicMachine: async (data: BasicMachine) => {
    return await request.put({ url: `/erp/basic-machine/update`, data })
  },

  // 删除ERP 基础资料模具
  deleteBasicMachine: async (id: number) => {
    return await request.delete({ url: `/erp/basic-machine/delete?id=` + id })
  },

  /** 批量删除ERP 基础资料模具 */
  deleteBasicMachineList: async (ids: number[]) => {
    return await request.delete({ url: `/erp/basic-machine/delete-list?ids=${ids.join(',')}` })
  },

  // 导出ERP 基础资料模具 Excel
  exportBasicMachine: async (params) => {
    return await request.download({ url: `/erp/basic-machine/export-excel`, params })
  },

// ==================== 子表（机器模具） ====================

  // 获得机器模具列表
  getBasicMachineMouldListByMachineId: async (machineId) => {
    return await request.get({ url: `/erp/basic-machine/basic-machine-mould/list-by-machine-id?machineId=` + machineId })
  }
}
